{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ce41ce71",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NN\n",
      "n\n",
      "russia--n-->russia\n",
      "NNS\n",
      "n\n",
      "men--n-->men\n",
      "VBG\n",
      "v\n",
      "running--v-->run\n",
      "NN\n",
      "n\n",
      "ate--n-->ate\n",
      "NN\n",
      "n\n",
      "saddest--n-->saddest\n",
      "NN\n",
      "n\n",
      "fancier--n-->fancier\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "__author__:shuangrui Guo\n",
    "__description__:\n",
    "\"\"\"\n",
    "from nltk import pos_tag\n",
    "from nltk.stem import WordNetLemmatizer\n",
    "from nltk.corpus import wordnet\n",
    " \n",
    "wnl = WordNetLemmatizer()\n",
    "# 获取单词的词性\n",
    "def get_wordnet_pos(tag):\n",
    "    if tag.startswith('J'):\n",
    "        return wordnet.ADJ\n",
    "    elif tag.startswith('V'):\n",
    "        return wordnet.VERB\n",
    "    elif tag.startswith('N'):\n",
    "        return wordnet.NOUN\n",
    "    elif tag.startswith('R'):\n",
    "        return wordnet.ADV\n",
    "    else:\n",
    "        return None\n",
    " \n",
    "#分别定义需要进行还原的单词与相对应的词性\n",
    "words = ['russia','men','running','ate','saddest','fancier']\n",
    "for i in range(len(words)):\n",
    "    print(pos_tag([words[i]])[0][1])\n",
    "    print(get_wordnet_pos(pos_tag([words[i]])[0][1]))\n",
    "    print(words[i]+'--'+get_wordnet_pos(pos_tag([words[i]])[0][1])+'-->'+wnl.lemmatize(words[i],get_wordnet_pos(pos_tag([words[i]])[0][1])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5e6fb4cc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
